package com.wyh.utils.sqlUtils.announcement;

import com.wyh.entity.Announcements;

import javax.validation.constraints.NotNull;

public class updateAnnouncementSqlDynamic {
    public String updateDynamic(@NotNull Announcements announcements) {
        StringBuilder builder = new StringBuilder();
        if (announcements.getInformation()!=null){
            if (builder.length() > 0) {
                builder.append(", ");
            }
            builder.append("information = #{information}");
        }
        if (announcements.getType()!=null){
            if (builder.length() > 0) {
                builder.append(", ");
            }
            builder.append("type = #{type}");
        }
        if (announcements.getTime()!=null){
            if (builder.length() > 0) {
                builder.append(", ");
            }
            builder.append("time = #{time}");
        }
        if (announcements.getRemark()!=null){
            if (builder.length() > 0) {
                builder.append(", ");
            }
            builder.append("remark = #{remark}");
        }

        StringBuilder sql = new StringBuilder();
        sql.append(" update announcements set ");
        sql.append(builder);
        sql.append(" WHERE id = #{id}; ");

        System.out.println(sql);
        return sql.toString();

    }
}
